package com.cskaoyan.service.wx.impl;

import com.cskaoyan.bean.MarketFeedback;
import com.cskaoyan.bean.MarketUser;
import com.cskaoyan.mapper.MarketFeedbackMapper;
import com.cskaoyan.service.wx.WXFeedbackService;
import org.apache.shiro.SecurityUtils;
import org.apache.shiro.subject.PrincipalCollection;
import org.apache.shiro.subject.Subject;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.validation.annotation.Validated;

import java.util.Date;

import java.util.Date;

/**
 * @author Yan Dexuan
 * @since 2022/06/29 10:25
 */

@Service
public class WXFeedbackServiceImpl implements WXFeedbackService {

    @Autowired
    MarketFeedbackMapper feedbackMapper;

    /**
     * 添加用户意见反馈。
     * @param marketFeedback
     * @return java.lang.Integer
     * @author Yan Dexuan
     * @since 2022/06/29 11:15
     */
    @Override
    public Integer feedbackSubmit(MarketFeedback marketFeedback) {

        Subject subject = SecurityUtils.getSubject();
        //MarketUser marketUser = (MarketUser) subject.getPrincipals().getPrimaryPrincipal();
        PrincipalCollection principals = subject.getPrincipals();
        if (principals.isEmpty()){
            return 501;
        }

        MarketUser marketUser = (MarketUser) principals.getPrimaryPrincipal();

        marketFeedback.setUserId(marketUser.getId());
        marketFeedback.setUsername(marketUser.getUsername());
        marketFeedback.setAddTime(new Date());
        marketFeedback.setUpdateTime(new Date());
        marketFeedback.setDeleted(false);

        int rows = feedbackMapper.insertSelective(marketFeedback);
        return rows;
    }

}
